package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.mapper.PropertyFeeMapper;
import com.wang.entity.PropertyFee;
import com.wang.service.PropertyFeeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
* @author 33115
* @description 针对表【property_fee】的数据库操作Service实现
* @createDate 2024-06-17 11:12:44
*/
@Service
public class PropertyFeeServiceImpl extends ServiceImpl<PropertyFeeMapper, PropertyFee>
    implements PropertyFeeService{
@Resource
PropertyFeeMapper propertyFeeMapper;
    @Override
    public List<PropertyFee> getPropertyFee(String ptitle, LocalDateTime startDate, LocalDateTime endDate) {
        LambdaQueryWrapper<PropertyFee> queryWrapper = new LambdaQueryWrapper<>();
        System.out.println(StringUtils.isNotBlank(ptitle));
        // 分别检查并设置查询条件
        if (StringUtils.isNotBlank(ptitle)) {
            queryWrapper.like(PropertyFee::getPTitle, "%" + ptitle + "%"); // 根据标题模糊匹配
        }

        if (startDate != null && endDate != null) {
            queryWrapper.between(PropertyFee::getPaymentTime, startDate, endDate); // 根据发布时间筛选
        }

        // 确保至少有一个查询条件被设置
        if (queryWrapper.isEmptyOfWhere()) {
            throw new IllegalArgumentException("至少需要提供标题关键词或时间范围进行查询");
        }

        return list(queryWrapper);
    }
}




